package pl.edu.pk.cc.client.worker;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
import javax.swing.JLabel;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JTextPane;
import javax.swing.JButton;
import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;


public class CCWorkerPanel extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7485607058571684352L;
	private JPanel contentPane;
	private DefaultListModel listModel;
	JTextPane textPane = new JTextPane();
	ListSelectionModel listSelectionModel;
	JList  list;
	static CCWorkerPanel frame = new CCWorkerPanel();
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			
		});
	}

	/**
	 * Create the frame.
	 */
	public CCWorkerPanel() {
		
		
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 850, 500);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblIdworker = new JLabel("ID_worker, imie i nazwisko");
		lblIdworker.setFont(new Font("Times New Roman", Font.BOLD, 30));
		lblIdworker.setBounds(225, 35, 400, 51);
		contentPane.add(lblIdworker);
		
		listModel = new DefaultListModel();
		listModel.addElement("Jane Doe");
		listModel.addElement("John Smith");
		listModel.addElement("Kathy Green");
		
		
		list = new JList(listModel);
		list.setBounds(286, 160, 290, 268);
		list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		list.setLayoutOrientation(JList.VERTICAL);
		
		list.setVisibleRowCount(-1);
		listSelectionModel = list.getSelectionModel();
        listSelectionModel.addListSelectionListener(
                new SharedListSelectionHandler());
		
		contentPane.add(list);
		
		textPane.setBounds(10, 160, 215, 268);
		contentPane.add(textPane);
		
		JTextPane textPane_1 = new JTextPane();
		textPane_1.setBounds(641, 160, 183, 268);
		contentPane.add(textPane_1);
		
		JLabel lblProjektyDoRealizacji = new JLabel("Projekty do realizacji");
		lblProjektyDoRealizacji.setFont(new Font("Tahoma", Font.PLAIN, 24));
		lblProjektyDoRealizacji.setBounds(315, 120, 232, 29);
		contentPane.add(lblProjektyDoRealizacji);
		
		JLabel lblInformacjeOProjekcie = new JLabel("Informacje o projekcie");
		lblInformacjeOProjekcie.setFont(new Font("Tahoma", Font.PLAIN, 20));
		lblInformacjeOProjekcie.setBounds(10, 120, 215, 27);
		contentPane.add(lblInformacjeOProjekcie);
		
		JLabel lblProfil = new JLabel("Profil");
		lblProfil.setFont(new Font("Tahoma", Font.PLAIN, 20));
		lblProfil.setBounds(686, 123, 118, 27);
		contentPane.add(lblProfil);
		
		JButton btnZamknij = new JButton("Zamknij");
		btnZamknij.setBounds(0, 0, 89, 23);
		btnZamknij.addActionListener(new ExitListener());
		contentPane.add(btnZamknij);
		
		JButton btnWstecz = new JButton("Wstecz");
		btnWstecz.setBounds(92, 0, 89, 23);
		contentPane.add(btnWstecz);
		
		JButton btnRealizuj = new JButton("Realizuj");
		btnRealizuj.setBounds(389, 430, 89, 23);
		btnRealizuj.addActionListener(new RealizujListener());
		contentPane.add(btnRealizuj);
		
		
		
		btnWstecz.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				
				
			}
		});
		
	}
	class SharedListSelectionHandler implements ListSelectionListener {
        public void valueChanged(ListSelectionEvent e) {
        
        	
        	 
        	String name = (String) list.getSelectedValue();
        	textPane.setText( name );
        	textPane.updateUI();
        
        
        }
        
    }
	private Object[] option = {"Nie", "Tak"};
	class ExitListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
        	int val = javax.swing.JOptionPane.showOptionDialog(null, "Jestes pewien, ze chcesz zamknac program?",
                    "Exit", javax.swing.JOptionPane.YES_NO_OPTION,
                    javax.swing.JOptionPane.QUESTION_MESSAGE, null, option, option[0]);
            
            if(val == 1) {
                System.exit(0);
            }
        }
    }
	class RealizujListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
        	try {
				CCWorkerCallPanel frame2 = new CCWorkerCallPanel();
				frame2.setVisible(true);
				CCWorkerPanel.this.setVisible(false);
			} catch (Exception ee) {
				ee.printStackTrace();
			}
        	
        }
    }
	
}
